/**
 * @fileOverview
 * @author iNahoo
 * @since 2019/11/12.
 */
"use strict";

const {sleep} = require('../utils');
const PCRScreen = require('./screen');
const M = require('./mouse');

class PCR {
    constructor(x, y, width, height) {
        this.x = x;
        this.y = y;
        this.w = width;
        this.h = height;

        this.screen = new PCRScreen(x, y, width, height);
    }

    async run(task) {
        await task(this, this.screen, M);
    }

    async tryAgain() {
        const p1 = this.screen.getNextButtonPos();
        await M.click(p1);

        await sleep(1e3);
        await M.click({
            x: this.screen.x(660),
            y: this.screen.y(293),
        });

        await sleep(1e3);

        const p2 = this.screen.getAgainButtonPos();
        await M.click(p2);

        await sleep(1e3);

        const p3 = this.screen.getAgainConfirmButtonPos();
        await M.click(p3);
    }

    static save() {
        M.save();
    }

    static restore() {
        M.restore();
    }
}


module.exports = PCR;